package com.foreknow.controller;

import net.sf.json.JSONArray;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class GetValueAction extends HttpServlet{
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        PrintWriter out = resp.getWriter();
        String action = req.getParameter("action");
        if(action.equals("getvalue")){
            String[] str = getValue();
            JSONArray jsonArray = JSONArray.fromObject(str);
            out.println(jsonArray.toString());
        }

    }

    public String[] getValue() {
        String[] str = new String[4];
        str[0] = "Java";
        str[1] = "NodeJs";
        str[2] = "ES6";
        str[3] = "AngularJs";
        return str;
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp);
    }
}